extern crate bindgen;

use std::env;
use std::path::PathBuf;

fn main() {
    // 生成C++头文件的Rust绑定
    let bindings = bindgen::Builder::default()
        .header("src/cpp/include/bingen_cpp_string.h")
        .generate()
        .expect("Unable to generate bindings");

    let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
    bindings
        .write_to_file(out_path.join("cpp_bindings.rs"))
        .expect("Couldn't write bindings!");

    // 告诉cargo重新运行build.rs当C++头文件改变时
    println!("cargo:rerun-if-changed=cpp/include/my_cpp_lib.h");

    // 编译C++代码
    cc::Build::new()
        .file("src/cpp/src/bingen_cpp_string.cpp")
        .include("src/cpp/include")
        .compile("my_cpp_lib");
}